From cfe2a5039b75f93d5e5d712b91a9d3d693d5b10d Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Sat, 12 Apr 2008 18:04:46 +0000 Subject: [PATCH] * Cache image redirects (and enable them) --- includes/Article.php | 2 ++ includes/DefaultSettings.php | 6 ------ includes/filerepo/FileRepo.php | 9 +++++++++ includes/filerepo/LocalRepo.php | 27 ++++++++++++++++++++++++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index dbb668a2c7..f49c1c40d8 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1160,6 +1160,8 @@ class Article { $dbw->delete( 'redirect', $where, __METHOD__); } + if( $this->getTitle()->getNamespace() == NS_IMAGE ) + RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() ); wfProfileOut( __METHOD__ ); return ( $dbw->affectedRows() != 0 ); } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index aa16f51566..386253b983 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -461,12 +461,6 @@ $wgHashedSharedUploadDirectory = true; */ $wgRepositoryBaseUrl = "http://commons.wikimedia.org/wiki/Image:"; -/** - * File redirects - * If enabled, MediaWiki checks redirects in Image: namespace. - */ -$wgFileRedirects = false; - # # Email settings # diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index a5ef5e5d25..666dc7ba70 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -435,5 +435,14 @@ abstract class FileRepo { function checkRedirect( $title ) { return false; } + + /** + * Invalidates image redirect cache related to that image + * STUB + * + * @param Title $title Title of image + */ + function invalidateImageRedirect( $title ) { + } } diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index f71cf706c6..a59da29fbf 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -95,17 +95,29 @@ class LocalRepo extends FSRepo { } function checkRedirect( $title ) { - global $wgFileRedirects; + global $wgFileRedirects, $wgMemc; if( !$wgFileRedirects ) { return false; } + if( is_string( $title ) ) { + $title = Title::newFromTitle( $title ); + } if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) { $title = Title::makeTitle( NS_IMAGE, $title->getText() ); } - + + $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); + $cachedValue = $wgMemc->get( $memcKey ); + if( $cachedValue ) { + return Title::newFromDbKey( $cachedValue ); + } elseif( $cachedValue == ' ' ) { # FIXME: ugly hack, but BagOStuff caching seems to be weird and return false if !cachedValue, not only if it doesn't exist + return false; + } + $id = $this->getArticleID( $title ); if( !$id ) { + $wgMemc->set( $memcKey, " ", 9000 ); return false; } $dbr = $this->getSlaveDB(); @@ -115,9 +127,18 @@ class LocalRepo extends FSRepo { array( 'rd_from' => $id ), __METHOD__ ); + + if( $row ) $targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title ); + $wgMemc->set( $memcKey, ($row ? $targetTitle->getPrefixedDBkey() : " "), 9000 ); if( !$row ) { return false; } - return Title::makeTitle( $row->rd_namespace, $row->rd_title ); + return $targetTitle; + } + + function invalidateImageRedirect( $title ) { + global $wgMemc; + $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); + $wgMemc->delete( $memcKey ); } } -- 2.20.1